import React from "react";
import { inject, observer } from "mobx-react";
import { message } from "antd";

const HOCStoreShowSet = (WarpComponent) => {
  @inject("setStoreInfo")
  @observer
  class ElementComponent extends React.Component {
    componentDidMount() {
      let { getStoreShowSet } = this.props.setStoreInfo;
      //查询显示设置
      getStoreShowSet().then((data) => {
        if (data.data.code === 200) {
          let allData = data.data.data[0];
          this.setForm(allData);
        } else {
          message.error("请求数据失败");
        }
      });
    }
    setForm = (obj) => {
      let { formOne } = this.refs.form.refs;
      formOne.setFieldsValue(obj);
    };
    submit = () => {
      let { updateStoreShowSet } = this.props.setStoreInfo;
      let { formOne } = this.refs.form.refs;
      let pdsNfsr = formOne.getFieldValue('pdsNfsr') //销量排行数量
      let pdsNoc = formOne.getFieldValue('pdsNoc') //评论数量
      let pdsTnl = formOne.getFieldValue('pdsTnl') //商品名长度
      let pdsDqoccp = formOne.getFieldValue('pdsDqoccp') //商品分类页列表显示数量
      let pdsHfr = formOne.getFieldValue('pdsHfr') //助力免单规则
      let obj = {
        pdsId:1,
        pdsNfsr,
        pdsNoc,
        pdsTnl,
        pdsDqoccp,
        pdsHfr
      }
      updateStoreShowSet(obj).then(data=>{
          if (data.data.code === 200) {
              message.success('更新数据成功')
          }else{
              message.error('更新数据失败')
          }
      })
    };
    render() {
      let methods = {
        submit: this.submit,
      };
      return (
        <div>
          <WarpComponent ref="form" {...methods}></WarpComponent>
        </div>
      );
    }
  }
  return ElementComponent;
};

export default HOCStoreShowSet;
